/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.project;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

import edu.uwm.universitydb.framework.transactional.db.command.impl.TransactionalDataManipulationCommandBase;
import edu.uwm.universitydb.model.Project;

/**
 * <code>InsertProjectCommand</type>
 * 
 * @author Shyam Nair
 */
public class InsertProjectCommand extends TransactionalDataManipulationCommandBase
{

    /** static string holding insert query */
    private static final String INSERT_SQL =
        "insert into university.project (pno, sponser, starting_date, ending_date, budget) values (?, ?, ?, ?, ?);";

    /** attribute holding the project information to be inserted */
    private final Project mProject;

    /**
     * @param project
     */
    public InsertProjectCommand(final Project project)
    {
        mProject = project;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return INSERT_SQL;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        // set project number
        final Integer projNum = mProject.getProjectNum();
        pStmt.setInt(1, projNum);
        // set sponsor
        final String sponsor = mProject.getSponsor();
        pStmt.setString(2, sponsor);
        // set start date
        final Date startDate = mProject.getStartDate();
        final Long startTime = startDate.getTime();
        final java.sql.Date startDateVal = new java.sql.Date(startTime);
        pStmt.setDate(3, startDateVal);
        // set end date
        final Date endDate = mProject.getEndDate();
        final Long endTime = endDate.getTime();
        final java.sql.Date endDateVal = new java.sql.Date(endTime);
        pStmt.setDate(4, endDateVal);
        // set budget
        final Integer budget = mProject.getBudget();
        pStmt.setInt(5, budget);
    }

}
/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 19, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */